<template>
  <div class="login">
    <div class="login-box">
      <!-- 头部区域 -->
      <div class="header-login">
        <img src="../assets/logo.png" class="img-login">
      </div>
      <!-- 表单区域 -->
      <div class="form-login">
        <!-- 登录名 -->
        <div class="form-group">
          <label for="username">登录名称</label>
          <input type="text" class="form-control" id="username" placeholder="请输入用户名" autocomplete="off" v-model.trim="username" />
        </div>
        <!-- 登录密码 -->
        <div class="form-group">
          <label for="password">登录密码</label>
          <input type="text" class="form-control" id="password" placeholder="请输入登录密码" v-model.trim="password" />
        </div>
        <!-- 登录和重置按钮 -->
        <div class="form-group-btn">
          <button type="button" class="resBtn" @click="reset">重置</button>
          <button type="button" class="comBtn" @click="login">登录</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MyLogin',
  data() {
    return {
      username: '',
      password: ''
    };
  },
  methods: {
    // 重置
    reset() {
      this.username = '';
      this.password = '';
    },
    // 登录
    login() {
      if (this.username == 'admin' && this.password == 'admin') {
        // 登录成功
        // 1.存储token  2.跳转到后台主页
        localStorage.setItem('token', 'Bearer xxxx');
        this.$router.push('/home');
      } else {
        // 登录失败
        alert('用户名或密码错误');
        this.username = '';
        this.password = '';
        localStorage.removeItem('token');
      }
    }
  }
};
</script>

<style lang="less" scoped>
.login {
  background-color: rgb(112, 92, 92);
  height: 100%;
  .login-box {
    width: 400px;
    height: 250px;
    background-color: rgb(230, 236, 201);
    border-radius: 3px;
    position: absolute;
    left: 40%;
    top: 40%;
  }
  .header-login {
    width: 80px;
    height: 80px;
    position: absolute;
    left: 40%;
    top: -20px;
    .img-login {
      width: 80px;
      height: 80px;
    }
  }
  .form-login {
    margin-top: 110px;
    margin-left: 60px;
  }
  .form-group {
    font-size: 18px;
    margin-bottom: 10px;
    .form-control {
      margin-left: 8px;
      width: 200px;
      height: 20px;
    }
  }
  .form-group-btn {
    margin-top: 30px;
    margin-left: 180px;
    .resBtn {
      width: 50px;
      height: 26px;
      margin-right: 5px;
      background-color: rgb(184, 166, 166);
      color: aliceblue;
      border: none;
    }
    .comBtn {
      width: 50px;
      height: 26px;
      background-color: rgb(22, 146, 230);
      color: aliceblue;
      border: none;
    }
  }
}
</style>